﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cludg.Services.Security
{
	using Domain.Users;
	using Domain.Content;
	using Permissions;

	public class Authorization : IAuthorization
	{
		protected readonly List<Permission> PermissionList = new List<Permission>();

		public Authorization(IEnumerable<IPermissionProvider> providers)
		{
			PermissionList.Clear();
			foreach (var provider in providers)
				PermissionList.AddRange(provider.GetPermissions());
		}

		public IEnumerable<Permission> Permissions { get { return PermissionList; } }

		public bool HasRights(User user, string permissionName, IContent content)
		{
			return Permissions.Where(p => p.Name == permissionName).Any(p => p.UserHasPermission(user, content));
		}
	}
}
